<?php #20070426


/************************************************************************/
/* FrameWork  test preview                                              */
/* ==================================================================== */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/

// crea se non c'e' la cartella delle chiamate tra utenti
if(!file_exists("datas/blocks"))mkdir("datas/blocks");
if(!file_exists("datas/blocks/$block"))mkdir("datas/blocks/$block");
if(!file_exists("datas/blocks/$block/calls"))mkdir("datas/blocks/$block/calls");

// crea l'avviso
$user=user_getuser();

$message=split(":",$_GET['message']);
if ($message[0]==$user && $user!="" ){
    $fp=fopen("datas/blocks/$block/calls/".$message[1],"w");
    fwrite($fp,"ti ha cercato: ".$message[0]);
    fclose($fp);
}
// verifica se qualcuno ti ha cercato
if ($user!=""){
    if (file_exists("datas/blocks/$block/calls/$user")){//se esiste il file con il tuo nome vuol dire che qualcuno ti ha visto e cercato
	if ($_GET['ahah']==1){
	    echo "
	    <div class='table'style=\"background-color: #ffffdf; \">

	    <object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"
	    codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=8 height=8>
		<param name=movie value=\"$path/$block/campanello.swf\"> <param name=quality value=high> <param name=bgcolor value=#ffffff>
		<embed src=\"$path/$block/campanello.swf\" quality=high bgcolor=#ffffff  width=8 height=8 type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash\">
		</embed>
	    </object>

	    <center>
	    <br />
	    <h4>ti stanno cercando<h4><br />
	    <br/>
	    <a href='index.php' style=\"color: 0;\" >OK</a>
	    </center>
	    </div>
	    ";
	}
	else{
	    $message=explode(" ",join(file("datas/blocks/$block/calls/$user")));
	    echo"<script>alert('".implode(" ",$message)."');</script>";// ti mostra chi ti ha chiamato
	    if (count($message)==4){
		$fp=fopen("datas/blocks/$block/calls/".$message[3],"w");
		fwrite($fp,"il messaggio e\' stato consegnato a:".user_getuser());
		fclose($fp);
	    }
	    unlink("datas/blocks/$block/calls/$user");// poiche e' stato visualizzato il messaggio viene cancellato
	}
    }
}


//------------------------------------------------------------------------

function admin_online(){
    $registered_ip=@join(@file("datas/sb/".sb_get()."/admin_ip"));
    if ($registered_ip=="")return "errore";

    if ($registered_ip=="no-ip")
	return "non in linea";
    else
	return "in linea";

}
//------------------------------------------------------------------------

function user_online($path){
    $type="global";
    $year=date("Y");
    $month=date("m");
    $day=date("d");

    if (file_exists("datas/sb/".sb_get()."/logs/global/$year/$month/$day/")){
	$fd=opendir("datas/sb/".sb_get()."/logs/global/$year/$month/$day/");
	while (false !== ($nf= readdir($fd))){
	    if($nf[0]!='.' ){
		if((time()-@filectime("datas/sb/".sb_get()."/logs/global/$year/$month/$day/$nf"))<60 && $nf!="temp"){
		    include "datas/sb/".sb_get()."/logs/global/$year/$month/$day/$nf";

		    /* da usare con i log in formato xml
		    $string=join(file("$name"));
		    $key=ereg_replace(".*<key>","",$string);
		    $key=ereg_replace("</key>.*","",$key);

		    $USER[$key]=ereg_replace(".*<USER>","",$string);
		    $USER[$key]=ereg_replace("</USER>.*","",$USER[$key]);

		    $URI[$key]=ereg_replace(".*<URI>","",$string);
		    $URI[$key]=ereg_replace("</URI>.*","",$URI[$key]);
		    */
		}
	    }
	}
    }


    if (count($USER))
    foreach($USER as $k =>$user ){
	$tmp=explode("||",$user);$usr=$tmp[0];
	$kt=explode(".",$k);
	if ($usr!=""){
	    if (strpos($URI[$k],"user_op=logout")!=0){
		unset($user_list[$usr]);
	    }
	    else{
		$user_list[$usr]=$k;
	    }
	}

    }
    $user=user_getuser();
    if ($user!="")
	$user_list[$user]=date("H.i.s");

    $ret=count($user_list)."<br/>";

    if (count($user_list)>0){
	foreach($user_list as $user_element=>$k){
	    if(file_exists("datas/sb/".sb_get()."/users/$user_element"))
		include "datas/sb/".sb_get()."/users/$user_element";
	    if( user_getuser() != $user_element){
		$chiama="<a href='index.php&message=".user_getuser().":$user_element'>chiama</a>";
		if (strpos($chiama,"?")==0)$chiama=str_replace("&","?",$chiama);
	    }
	    else{
		$chiama="";
	    }
	    if ($user_avatar!="") {
		if (substr($user_avatar,0,5)=="http:"){
		    $ret=$ret."<img src='$user_avatar' width='16' />$user_element $chiama<br />";
		}
		else {
		    $ret=$ret."<img src='libs/avatars/$user_avatar' width='16' />$user_element $chiama<br />";
		}


	    }
	    else
		$ret=$ret."<img src='$path/images/usr-user.gif' />$user_element $chiama<br />";
	}
    }

    return $ret;
}
//------------------------------------------------------------------------

function guest_online(){
    $type="global";
    $year=date("Y");
    $month=date("m");
    $day=date("d");
    if (file_exists("datas/sb/".sb_get()."/logs/$type/$year/$month/$day")){
	$fd=opendir("datas/sb/".sb_get()."/logs/$type/$year/$month/$day/");
	while (false !== ($nf= readdir($fd))){
	    if($nf[0]!='.' && $nf!='temp'){
		include "datas/sb/".sb_get()."/logs/$type/$year/$month/$day/$nf";
		/* da usare con i log in formato xml
		$string=join(file("$name"));
		$key=ereg_replace(".*<key>","",$string);
		$key=ereg_replace("</key>.*","",$key);

		$USER[$key]=ereg_replace(".*<USER>","",$string);
		$USER[$key]=ereg_replace("</USER>.*","",$USER[$key]);

		$URI[$key]=ereg_replace(".*<URI>","",$string);
		$URI[$key]=ereg_replace("</URI>.*","",$URI[$key]);
		*/
	    }
	}
    }

    if (count($REMOTE_ADDR))
	foreach($REMOTE_ADDR as $k =>$remote_addr ){
	    $kt=explode(".",$k);
	    if ( $USER[$k] == "" )
		$guest_list[$remote_addr]=$k;
	    else
		unset ($guest_list[$remote_addr]);
	}

    if (user_getuser()=="")
	$guest_list[$_SERVER[REMOTE_ADDR]]=date("H.i.m");
    $ret= count($guest_list)."<br />";
    return $ret;
}
//------------------------------------------------------------------------


?>
<?php if ($_GET['ahah']!=1) { ?>
<div id="useronline">
<?php } ?>

<?php structure_openBlock("table block right useronline","User on line","$path/$block"); ?>

    <p>
	<img src="<?="$path/$block"?>/images/usr-admin.gif" /><b>admin:</b><?=admin_online();?><br />
	<img src="<?="$path/$block"?>/images/group-users.gif" /><b>users:</b><?=user_online("$path/$block");?>
	<br />
	<img src="<?="$path/$block"?>/images/group-guests.gif" /><b>guests:</b><?=guest_online();?>


    </p>

<?php structure_closeBlock(); ?>

<?php if ($_GET['ahah']!=1) { ?>
</div>
<?php } ?>

<script>
var id;

function useronline_update(){
    id=window.setTimeout("useronline_update();",24000);
    ahah("index.php?ahah=1&path=<?=$path?>&block=<?=$block?>", "useronline", 10, "POST", "");
}
id=window.setTimeout("useronline_update();",12000);
</script>

